<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>回调函数形式的ref</title>
  </head>
  <body>
    <div id="test"></div>
    <div id="test1"></div>
    <div id="test2"></div>

    <script
      src="https://unpkg.com/react@16/umd/react.development.js"
      crossorigin
    ></script>
    <script
      src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"
      crossorigin
    ></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
    <script type="text/babel"></script>
  </body>
  <script type="text/babel">
    //创建组件
    class Demo extends React.Component {
      state = { isHot: true };

      showInfo = () => {
        const { input } = this;
        alert(input.value);
      };
      weatherChange = () => {
        const { isHot } = this.state;
        //更新状态
        this.setState({ isHot: !isHot });
      };
      saveInput = (currentNode) => {
        //函数体
        this.input = currentNode;
        console.log("ahahahha", currentNode);
      };
      render() {
        const { isHot } = this.state;
        return (
          <div>
            <h1>今天天气很{isHot ? "炎热" : "凉爽"}</h1>
            {/*<input
              ref={(currentNode) => {
                this.input = currentNode;
                console.log("ahahahha", currentNode);
              }}
              type="text"
              name=""
              id=""
            />
            <br />
            <br />*/}
            <input ref={this.saveInput} type="text" name="" id="" />
            <br />
            <br />
            <button onClick={this.showInfo}>点我提示输入的数据</button>
            <button onClick={this.weatherChange}>点我切换天气</button>
          </div>
        );
      }
    }
    //渲染组件到页面
    ReactDOM.render(<Demo />, document.getElementById("test"));
  </script>
</html>
